package jedis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.ResourceBundle;

public class JedisUtil {

    private static JedisPool jedisPool = null;
    private static String host = null;
    private static Integer port = null;
    private static Integer maxTotal = null;
    private static Integer maxIdle = null;

    static {
        // 加载配置文件
        ResourceBundle resourceBundle = ResourceBundle.getBundle("redis");
        host = resourceBundle.getString("redis.host");
        port = Integer.valueOf(resourceBundle.getString("redis.port"));
        maxTotal = Integer.valueOf(resourceBundle.getString("redis.maxTotal"));
        maxIdle = Integer.valueOf(resourceBundle.getString("redis.maxIdle"));

        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(maxTotal);
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPool = new JedisPool(jedisPoolConfig, host, port);
    }

    public static Jedis getJedis() {
        return jedisPool.getResource();
    }

    public static void main(String[] args) {
        JedisUtil.getJedis();
    }

}
